package com.ruoyi.web.controller.arborrow;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.ArBorrowDetail;
import com.ruoyi.web.service.IArBorrowDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 借阅详情Controller
 *
 * @author ruoyi
 * @date 2022-02-15
 */
@RestController
@RequestMapping("/web/detail")
public class ArBorrowDetailController extends BaseController
{
    @Autowired
    private IArBorrowDetailService arBorrowDetailService;

    /**
     * 查询借阅详情列表
     */
    @PreAuthorize("@ss.hasPermi('web:detail:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArBorrowDetail arBorrowDetail)
    {
        startPage();
        List<ArBorrowDetail> list = arBorrowDetailService.selectArBorrowDetailList(arBorrowDetail);
        return getDataTable(list);
    }

    /**
     * 导出借阅详情列表
     */
    @PreAuthorize("@ss.hasPermi('web:detail:export')")
    @Log(title = "借阅详情", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ArBorrowDetail arBorrowDetail)
    {
        List<ArBorrowDetail> list = arBorrowDetailService.selectArBorrowDetailList(arBorrowDetail);
        ExcelUtil<ArBorrowDetail> util = new ExcelUtil<ArBorrowDetail>(ArBorrowDetail.class);
        return util.exportExcel(list, "detail");
    }

    /**
     * 获取借阅详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('web:detail:query')")
    @GetMapping(value = "/{recNo}")
    public AjaxResult getInfo(@PathVariable("recNo") String recNo)
    {
        return AjaxResult.success(arBorrowDetailService.selectArBorrowDetailById(recNo));
    }

    /**
     * 新增借阅详情
     */
    @PreAuthorize("@ss.hasPermi('web:detail:add')")
    @Log(title = "借阅详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArBorrowDetail arBorrowDetail)
    {
        return toAjax(arBorrowDetailService.insertArBorrowDetail(arBorrowDetail));
    }

    /**
     * 修改借阅详情
     */
    @PreAuthorize("@ss.hasPermi('web:detail:edit')")
    @Log(title = "借阅详情", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody ArBorrowDetail arBorrowDetail)
    {
        return toAjax(arBorrowDetailService.updateArBorrowDetail(arBorrowDetail));
    }

    /**
     * 删除借阅详情
     */
    @PreAuthorize("@ss.hasPermi('web:detail:remove')")
    @Log(title = "借阅详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recNos}")
    public AjaxResult remove(@PathVariable String[] recNos)
    {
        return toAjax(arBorrowDetailService.deleteArBorrowDetailByIds(recNos));
    }
}
